<div class="box box-skin main-content">	
	<div class="box-body no-padding">
	    <div id="toolbar">
			<div class="form-inline" role="form">
		    	<div class="form-group btn-group">
                    <button type="button" class="btn btn-default btn-flat" onclick="CRUDBorrowFunc(1);" title="添加"><i class="fa fa-plus"></i></button>
                    <button type="button" class="btn btn-default btn-flat" onclick="CRUDBorrowFunc(5);" title="批量删除"><i class="fa fa-trash"></i></button>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="likeMap[card_owner_name]" placeholder="持卡人姓名" />
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="likeMap['vipNo']" placeholder="会员卡号" />
                </div>
				<div class="form-group">
					<select class="form-control" name="equalMap[status]">
		                <option value="" selected="selected">全部状态</option>
		                <option value="0">等待确认</option>
						<option value ="1">正在借阅</option>
						<option value ="2">借阅完成</option>
						<option value ="3">借阅取消</option>
		                <option value="-1">已删除</option>
		            </select>
				</div>
		    	<div class="form-group btn-group">
                	<button type="button" class="btn btn-default btn-flat" onclick="searchFunc();" title="搜索"><i class="fa fa-search"></i></button>
                	<button type="button" class="btn btn-default btn-flat" onclick="reloadFunc();" title="重新加载"><i class="fa fa-refresh"></i></button>
                </div>
				<div class="form-group">
					<select class="form-control" id="exportDataType">
		                <option value="basic">导出当前页数据</option>
		                <option value="all">导出所有数据</option>
		                <option value="selected">导出选中数据</option>
		            </select>
				</div>
            </div>
	    </div>
		
		<table id="table"></table>
	</div>
</div>

<script type="text/javascript" src="__TMPL__Public/pages/borrow/borrow.js"></script>
<script type="text/javascript">
$(function() {
	$('#table').bootstrapTable({
		classes: 'table table-no-bordered table-hover',
		striped: true,
		toolbar: '#toolbar',
		showColumns: true,
	    showPaginationSwitch: true,
	    pagination: true,
		sidePagination: 'server',
		pageSize: 15,
		pageList: '[10, 15, 50, 100, All]',
		queryParams: queryParams,
		queryParamsType: 'limit',
		sortName: 'id',
		sortOrder: 'desc',
		url: "{:U('Borrow/Borrow/dataList')}",
	    idField: 'id',
        showExport: true,									// 是否显示导出
        exportDataType: $('#exportDataType').val(),			// 'basic', 'all', 'selected'
	    columns: [{
            field: 'state',
            checkbox: true,
            visible: false,
        //	width: '20%',
            align: 'left',
            valign: 'middle',
        }, {
	        title: 'ID',
	        field: 'id',
	        sortable: true,
            visible: false,
    	//	width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '持有人姓名',
	        field: 'card_owner_name',
	        sortable: true,
		//	width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '图书编码',
	        field: 'book_code',
		//	width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '书名',
	        field: 'book_name',
		//	width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
			title:'开始时间',
			field:'start_time',
	        sortable: true,
		//	width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
           		return value > '0000-00-00 00:00:00' ? value : '<span class="text-gray">无</span>';
    		},
		}, {
			title:'结束时间',
			field:'end_time',
	        sortable: true,
		//	width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
           		return value > '0000-00-00 00:00:00' ? value : '<span class="text-gray">无</span>';
    		},
	    }, {
	        title: '借阅状态',
	        field: 'status',
		//	width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
            	var str = '';
            	if (value == 0) {
            		str = '<span class="label label-warning">等待确认</span>';
            	} else if (value == 1) {
            		str = '<span class="label label-success">正在借阅</span>';
            	} else if (value == 2) {
            		str = '<span class="label label-info">借阅完成</span>';
            	} else if (value == 3) {
            		str = '<span class="label label-default">已取消</span>';
            	}
    			return str;
    		},
		}, {
            title: '操作',
            field: 'operate',
            width: '15%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
				var str = '';
				str += '<div class="btn-group">';
				if (row.status == 0) {
					str += '<button type="button" class="btn btn-default btn-xs" onclick="status(' + row.id + ', ' + index + ', 1);">确认</button>';
					str += '<button type="button" class="btn btn-default btn-xs" onclick="status(' + row.id + ', ' + index + ', 3);">取消借阅</button>';
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">还书</button>';
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">删除</button>';
				} else if (row.status == 1) {
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">确认</button>';
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">取消借阅</button>';
					str += '<button type="button" class="btn btn-default btn-xs" onclick="status(' + row.id + ', ' + index + ', 2);">还书</button>';
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">删除</button>';
				} else {
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">确认</button>';
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">取消借阅</button>';
					str += '<button type="button" class="btn btn-default btn-xs" disabled="disabled">还书</button>';
					str += '<button type="button" class="btn btn-default btn-xs" onclick="CRUDBorrowFunc(4, ' + row.id + ');">删除</button>';
				}
				str += '</div>';
				return str;
			},
        }],
	});
});

/* search */
function queryParams(params) {
    $('#toolbar').find('input[name], select[name]').each(function () {
        params[$(this).attr('name')] = $(this).val();
    });
    return params;
}

function searchFunc() {
	$('#table').bootstrapTable('selectPage', 1);			// IMPORTANT!!!  有刷新功能!!!
}

/* reload */
function reloadFunc() {
	$('#toolbar').resetForm();
	$('#table').bootstrapTable('selectPage', 1);
}
</script>
